package com.cosmos.mapdemo;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.tianditu.android.maps.GeoPoint;
import com.tianditu.android.maps.ItemizedOverlay;
import com.tianditu.android.maps.OverlayItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Leonardo on 2015/7/21.
 */
public class DemoMultipleItemOverlay extends ItemizedOverlay<OverlayItem> {
    private List<OverlayItem> GeoList = new ArrayList<>();
    private Context context;
    private double mLat1 = 39.90923;
    private double mLon1 = 116.397428;
    private double mLat2 = 39.9022;
    private double mLon2 = 116.3922;
    private double mLat3 = 39.917723;
    private double mLon3 = 116.3722;

    public DemoMultipleItemOverlay(Drawable marker, Context context) {
        super(boundCenterBottom(marker));
        this.context = context;

        // 用给定的经纬度构造GeoPoint，单位是微度 (度 * 1E6)
        GeoPoint p1 = new GeoPoint((int) (mLat1 * 1E6), (int) (mLon1 * 1E6));
        GeoPoint p2 = new GeoPoint((int) (mLat2 * 1E6), (int) (mLon2 * 1E6));
        GeoPoint p3 = new GeoPoint((int) (mLat3 * 1E6), (int) (mLon3 * 1E6));
        GeoList.add(new OverlayItem(p1, "T1", "point1"));
        GeoList.add(new OverlayItem(p2, "T2", "point2"));
        GeoList.add(new OverlayItem(p3, "T3", "point3"));

        // 一旦有了数据，在调用其它方法前，必须首先调用这个方法
        populate();
    }

    @Override
    public int size() {
        return GeoList.size();
    }

    @Override
    protected OverlayItem createItem(int i) {
        // 创建指定的条目，由父类调用
        return GeoList.get(i);
    }

    @Override
    protected  boolean onTap(int i) {
        /*
        在某个条目被点中时调用
         */
        Toast.makeText(context, GeoList.get(i).getSnippet(), Toast.LENGTH_SHORT).show();
        return true;
    }
}
